$(function () {
    let markId = getUrlString('markid');
    let userid;
    //加入群组
    $('#addGroup').click(function () {
        window.location.href = 'dancool://web=https://api.odancool.com/weixinapp/view/messages/addGroup.html?markid='+markId
    });
    //获取用户信息
    function getsetting () {
        getData('get','/niu/apiv3/member_getsetting.php',{'markid':markId},function (data) {
            console.log(data);
            userid = data.userid;
            getGroupList();
        })
    }
    getsetting();
    //获取群组列表
    function getGroupList() {
        getData('get','/niu/apiv3/member_jmessage_group.php?method=getUserGroups',{'userid':'djuser_'+userid},function (data) {
            console.log(data);
            let append = '';
            if (data.body.length === 0){
                $('.nullContent').show();
            }else {
                $('.nullContent').hide();
                $(data.body).each(function () {
                    append += '<li>' +
                        '       <input class="name" type="hidden" value="'+this.gid+'">'+
                        '            <div class="left">' +
                        '                <img src="../../res/img/messages/headPic.png" alt="">' +
                        '            </div>' +
                        '            <div class="right">'+this.name+'</div>' +
                        '        </li>'
                });
                $('#conversationList').append(append);
                //群聊消息
                $('#conversationList li').click(function () {
                    let toUserName = $(this).find('.name').val();
                    let userName = 'djuser_'+userid;
                    window.location.href = 'dancool://fullweb=https://api.odancool.com/weixinapp/view/messages/group.html?toUserName='+toUserName+'&userName='+userName
                });
            }
        })
    }
});